import Vue from 'vue';
import VueI18n from 'vue-i18n'; // set VueI18n
import 'normalize.css/normalize.css'; // A modern alternative to CSS resets

import Element, { Message } from 'element-ui';
import Clipboard from 'clipboard';
import 'element-ui/lib/theme-chalk/index.css';

import '@/styles/index.scss'; // global css

import App from './App';
import router from './router';
import store from './store';
import { install } from './build';

import './icons'; // icon
import './errorLog'; // error log
import './permission'; // permission control
// import './mock'
import './utils/under-helper';

import * as filters from './filters'; // global filters

install(Vue);

new Clipboard('.clipboard-btn').on('success', e => {
  Message.success('复制成功');
});

const { CONST_LIST = [] } = process.env;
CONST_LIST.forEach(item => {
  Object.defineProperty(Vue.prototype, item, {
    value: require(`./const/${item}.js`).default
  });
});

Vue.use(Element, {
  size: 'mini' // set element-ui default size
});
sessionStorage.setItem('lang', sessionStorage.getItem('lang') || 'CN');
Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: sessionStorage.getItem('lang'),
  messages: {
    CN: require('./lang/zh'), // 中文语言包
    EN: require('./lang/en') // 英文语言包
  }
});

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  i18n,
  store,
  template: '<App/>',
  components: { App }
});
